package com.seemsea.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityNotFoundException;

public interface IGenericDAO<T extends IGenericEntity<ID>,ID extends Serializable> {
	/**
     * Retrieve an persisted object using the given id as primary key.
     *
     * @param id object's primary key
     * @return object
     * @throws EntityNotFoundException -
     *             if not found
     */
    T load(ID id) throws EntityNotFoundException;

    /**
     * Retrieve an persisted object using the given id as primary key.
     *
     * Returns null if not found.
     *
     * @param id object's primary key
     * @return object
     */
    T get(ID id);

    /**
     * Retrieve an persisted objects using the given ids as primary keys.
     *
     * @param ids objects's ids
     * @return list of objects
     */
    List<T> get(ID... ids);

    /**
     * Retrieve all persisted objects.
     *
     * @return list of objects
     */
    List<T> getAll();

    /**
     * Save all changes made to an object.
     *
     * @param object object
     */
    void save(T object);

    /**
     * Save all changes made to objects.
     *
     * @param objects objects
     */
    void save(T... objects);

    /**
     * Remove an object by given id. Check if object is not default one.
     *
     * If entity implements <code>IHiddenable</code> then it is hidden instead of deleted.
     *
     * @param id object's pk
     * @throws UnsupportedOperationException - if entity is default one
     * @see IHiddenable
     */
    void delete(ID id) throws UnsupportedOperationException;

    /**
     * Remove objects by given ids. Check if all objects are not mark as default one.
     *
     * If objects implement <code>IHiddenable</code> then ther are hidden instead of deleted.
     *
     * @param ids objects's pk
     * @throws UnsupportedOperationException - if one of entities is default one
     * @see IHiddenable
     */
    void delete(ID... ids) throws UnsupportedOperationException;

    /**
     * Remove an object. Check if object is not default one.
     *
     * If object implements <code>IHiddenable</code> then it is hidden instead of deleted.
     *
     * @param object object
     * @throws UnsupportedOperationException - if entity is default one
     * @see IHiddenable
     */
    void delete(T object) throws UnsupportedOperationException;

    /**
     * Remove objects. Check if all objects are not mark as default one.
     *
     * If objects implement <code>IHiddenable</code> then they are hidden instead of deleted.
     *
     * @param objects objects
     * @throws UnsupportedOperationException - if one of entities is default one
     * @see IHiddenable
     */
    void delete(T... objects) throws UnsupportedOperationException;

    /**
     * Delete all objects, including default one.
     *
     * If objects implement <code>IHiddenable</code> then they are hidden instead of deleted.
     *
     * @see IHiddenable
     */
    void deleteAll();

    /**
     * Refresh a persistant object that may have changed in another thread/transaction.
     *
     * @param entity transient entity
     */
    void refresh(T entity);

    /**
     * Write to database anything that is pending operation and clear it.
     */
    void flushAndClear();
	
}
